# -*- coding: utf-8 -*-
# --------------------------------------
# @Time    : 2025/6/19 22:05
# @File    : __init__.py.py
# @Project : Practice_flask_0619
# @Author  : CHH
# @Desc    : Windows   文件描述
# @Copyright : © 2025 HORDOR . All rights reserved.
# @Version : 1.0.0
# --------------------------------------
from flask import Flask, session


def get_real_name():
    userinfo = session.get("user_info")
    if not isinstance(userinfo, dict) or "username" not in userinfo:
        return None
    return userinfo["username"]


def create_app():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'sdafj489955iixll'
    # app.config['SERVER_NAME'] = '127.0.0.1:5800'

    from .views import acount
    from .views import book_list
    app.register_blueprint(acount.ac_bp)
    # app.register_blueprint(acount.ac_bp, url_prefix='/account')   访问前加前缀/account,然后跟注册蓝图里的路由
    app.register_blueprint(book_list.od_bp)
    app.template_global()(get_real_name)

    return app
